{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 准备工作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "阿里研究院\n",
    "阿里健康\n",
    "阿里巴巴商学院\n",
    "阿里数据\n",
    "\n",
    "腾讯金融科技\n",
    "腾讯研究院\n",
    "腾讯媒体研究院\n",
    "腾讯云启研究院\n",
    "酷鹅用户研究院\n",
    "'''\n",
    "公众号 = \"广东省考试院\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "fn = { \"output\" : { \"公众号_htm_snippets\": \"data_raw_src/公众号_htm_snippets_{公众号}.tsv\",\n",
    "                    \"公众号_df\": \"data_raw_src/公众号_df_{公众号}.tsv\",\n",
    "                    \"公众号_xlsx\": \"data_sets/公众号_url_{公众号}.xlsx\" } \\\n",
    "      }"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 采集公众号（requests）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "修改cookie user-agent token fakeid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "5\n",
      "10\n",
      "15\n",
      "20\n"
     ]
    }
   ],
   "source": [
    "# 目标url\n",
    "\n",
    "import time\n",
    "import requests\n",
    "import pandas as pd\n",
    "import csv\n",
    "\n",
    "\n",
    "url = \"https://mp.weixin.qq.com/cgi-bin/appmsg\"\n",
    "\n",
    "# 使用Cookie，跳过登陆操作\n",
    "headers = {\n",
    "    \"Cookie\": \"pgv_pvid=8631327150; pgv_pvi=2058978304; RK=rbZE8zbccv; ptcz=19bfa3dc3f41362c54e96370b2258fa985acd535931b161464d0739fe6dc6bd2; tvfe_boss_uuid=76ac84cccebf753d; o_cookie=862705952; ua_id=VIxEaIPt2OU9U4jZAAAAAKP7JFLdEo1O8esTsikRXU4=; mm_lang=zh_CN; wxuin=67495605894623; ied_qq=o0862705952; openid2ticket_oO2oL6IdQpN584Hbswa91xL86Veo=U22+65YTXQHipudwLZUaljLIEE3yQ3pZ+8qI+p4tNOw=; openid2ticket_oHc2a5aoNqzR2Y1EotQ3FtR-ywVk=pLdY77Q2MHDv3Rb5pKjrCWyxGI1mh9yGRiHsuQlRmDc=; qq_openid=3EDD635F065C862ADD0C12C9E52BD281; qq_access_token=FF89787B883EABBE6F555DDC3EF6EB35; qq_client_id=101487368; pac_uid=3_3EDD635F065C862ADD0C12C9E52BD281; xw_main_login=qq; ptui_loginuin=862705952; pgv_si=s8042288128; uuid=ec3335fbeecd802c35a7b35bba400ff7; rand_info=CAESIDd6xvtWLTI5zcl/8nCqcJqICbhzmfNHDqJkZKpw8Ts0; slave_bizuin=3893062203; data_bizuin=3893062203; bizuin=3893062203; data_ticket=4wtrsNwnk5w8QcwXLZKTBnYpxbrJBFRuGt3Syf5QKRZ7ksXcLpuu2ayGpwVulGBm; slave_sid=ZG1oNUpydFZyMzVVUWRQSmdCT3BPdGtSTFI0aElrdms3cFBUZDJxSHlBT3pNc3JYekl1Z3o0NGFoVG9JSnR2c3pkbDJGTkFpSmtnWEV1M2lpVlJNZHMwUEdpeXViVEIzMVd2VHN4WXZJYXFsT0VYSzA4Y0NDR2ZRWFAzeXdpOVlNRWJFWEdLNDdocjlCZEh0; slave_user=gh_88bff70d1cee; xid=325480f3aee06b1ddbfc5324941bb766\",\n",
    "    \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36\"}\n",
    "\n",
    "data = {\n",
    "    \"token\": \"1334741277\",\n",
    "    \"lang\": \"zh_CN\",\n",
    "    \"f\": \"json\",\n",
    "    \"ajax\": \"1\",\n",
    "    \"action\": \"list_ex\",\n",
    "    \"begin\": \"0\",\n",
    "    \"count\": \"5\",\n",
    "    \"query\": \"\",\n",
    "    \"fakeid\": \"MjM5NDI5NjIwNQ==\",\n",
    "    \"type\": \"9\",\n",
    "}\n",
    "\n",
    "\n",
    "\n",
    "content_list=[]\n",
    "\n",
    "for i in range(5):\n",
    "    data[\"begin\"] = i*5\n",
    "    print(data[\"begin\"])\n",
    "    time.sleep(3)\n",
    "    # 使用get方法进行提交\n",
    "    content_json = requests.get(url, headers=headers, params=data).json()\n",
    "#     print(content_json)\n",
    "    # 返回了一个json，里面是每一页的数据\n",
    "    for item in content_json[\"app_msg_list\"]:\n",
    "    # 提取每页文章的标题及对应的url\n",
    "        items = []\n",
    "        items.append(item[\"title\"])\n",
    "        items.append(item[\"link\"])\n",
    "        items.append(item[\"create_time\"])\n",
    "        content_list.append(items)\n",
    "\n",
    "\n",
    "name=['title','link','create_time']\n",
    "test=pd.DataFrame(columns=name,data=content_list)\n",
    "with pd.ExcelWriter(fn[\"output\"][\"公众号_xlsx\"].format(公众号=\"肥志\")) as writer:\n",
    "    test.to_excel(writer)\n",
    "\n",
    "# test.to_csv(\"../微信公众号爬虫_zhichao/南方周末.csv\",mode='a',encoding='utf-8')\n",
    "# print(\"保存成功\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 采集公众号（selenium）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from lxml.html import fromstring\n",
    "import time\n",
    "from random import random\n",
    "\n",
    "# when selenium main_content is used\n",
    "# Parses an HTML document from a string constant.  Returns the root nood\n",
    "# root = fromstring(df.loc[1,\"html_snippets\"]) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 使用Selenium\n",
    "* 要更改 opts.binary_location 至自己本地的Chrome浏览器，建议portable\n",
    "* Chrome浏览器 和 chromedriver.exe要同版本号到小数后一位\n",
    "* 要确保可以 开启浏览器机器人\n",
    "* 要确保浏览器机器人 可以打开网页 driver.get(\"https://mp.weixin.qq.com\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from selenium import webdriver\n",
    "from selenium.webdriver.common.desired_capabilities import DesiredCapabilities\n",
    "\n",
    "#caps=dict()\n",
    "#caps[\"pageLoadStrategy\"] = \"none\"   # Do not wait for full page load\n",
    "\n",
    "opts = webdriver.ChromeOptions()\n",
    "opts.add_argument('--no-sandbox')#解决DevToolsActivePort文件不存在的报错\n",
    "opts.add_argument('window-size=1920x3000') #指定浏览器分辨率\n",
    "opts.add_argument('--disable-gpu') #谷歌文档提到需要加上一这个属性来规避bug\n",
    "opts.add_argument('--hide-scrollbars') #隐藏滚动条, 应对些特殊页面\n",
    "#opts.add_argument('blink-settings=imagesEnabled=false') #不加载图片, 提升速度\n",
    "#opts.add_argument('--headless') #浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败\n",
    "\n",
    "opts.binary_location = r\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" \n",
    "\n",
    "# \"H:\\_coding_\\Gitee\\InternetNewMedia\\CapstonePrj2016\\chromedriver.exe\"  \n",
    "driver = webdriver.Chrome( options = opts) #desired_capabilities=caps,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.get(\"https://mp.weixin.qq.com\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 填表登入"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "selenium 的定位方法\n",
    "* find_element_by_id &ensp;&ensp;&ensp;  根据标签id定位\n",
    "* find_element_by_name   &ensp;&ensp;&ensp; 根据标签的name定位\n",
    "* find_element_by_xpath  &ensp;&ensp;&ensp; 根据xpath定位\n",
    "* find_element_by_link_text  &ensp;&ensp;&ensp; 通过文字链接来定位元素\n",
    "* find_element_by_partial_link_text  &ensp;&ensp;&ensp;  通过文字链接来定位元素\n",
    "* find_element_by_tag_name  &ensp;&ensp;&ensp;  根据标签的名字定位\n",
    "* find_element_by_class_name  &ensp;&ensp;&ensp; 通过class name 定位\n",
    "* find_element_by_css_selector  &ensp;&ensp;&ensp;  根据元素属性来定位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "payload =  {\"account\": \"649905644@qq.com\", \"password\": \"tyq14240TYQ\"}\n",
    "# payload =  {\"account\": \"NFUHacks@163.com\", \"password\": \"NFU706947580\"}\n",
    "driver.find_element_by_xpath('//div[@class=\"login__type__container login__type__container__scan\"]/a').click()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "WebDriver 常用方法：\n",
    "* clear()清楚文本\n",
    "* send_keys(values)模拟按键输入\n",
    "* click()模拟点击\n",
    "* submit模拟提交"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.find_element_by_xpath('//form[@class=\"login_form\"]//input[@name=\"account\"]').clear()\n",
    "driver.find_element_by_xpath('//form[@class=\"login_form\"]//input[@name=\"account\"]').send_keys(payload['account'])\n",
    "driver.find_element_by_xpath('//form[@class=\"login_form\"]//input[@name=\"password\"]').clear()\n",
    "driver.find_element_by_xpath('//form[@class=\"login_form\"]//input[@name=\"password\"]').send_keys(payload['password'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.find_element_by_xpath('//div[@class=\"login_btn_panel\"]/a').click()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 点选单"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "其他常用方法\n",
    "* size：返回元素的尺寸\n",
    "* text：获取元素的文本\n",
    "* get_attribute：获取属性值  &ensp;&ensp;&ensp; get_attribute('innerHTML')获取元素内的全部HTML\n",
    "* is_displayed()：设置该元素用户是否可见"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'展开'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "element = driver.find_element_by_xpath('//a[@id=\"m_open\"]')\n",
    "element.click()\n",
    "main_content = element.get_attribute('innerHTML')\n",
    "main_content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.execute_script(\"window.scrollTo(0,document.body.scrollHeight)\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'https://mp.weixin.qq.com/cgi-bin/appmsg?begin=0&count=10&t=media/appmsg_list&type=10&action=list&token=2044043607&lang=zh_CN'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "element = driver.find_element_by_xpath('//li[@title[contains(.,\"素材管理\")]]/a') \n",
    "# main_content = element.get_attribute('innerHTML')\n",
    "# main_content\n",
    "url2= element.get_attribute(\"href\")\n",
    "url2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.get(url2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 新建图文消息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "element = driver.find_element_by_xpath('//*[text()[contains(.,\"新建图文消息\")]]') \n",
    "main_content = element.get_attribute('innerHTML')\n",
    "main_content\n",
    "element.click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['CDwindow-BEE3DB03F2EEA9D379594CE66676FC2E', 'CDwindow-1D146DBD57C62871A8AD9F8F8F557D32']\n"
     ]
    }
   ],
   "source": [
    "print (driver.window_handles)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 新建图文消息开了另一分视窗，所以要切换 switch_to \n",
    "driver.switch_to.window(driver.window_handles[-1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 超链接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                超链接              \n"
     ]
    },
    {
     "ename": "ElementNotInteractableException",
     "evalue": "Message: element not interactable\n  (Session info: chrome=81.0.4044.138)\n",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mElementNotInteractableException\u001b[0m           Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-20-a5d4c26b2641>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[0mmain_content\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0melement\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_attribute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'innerHTML'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmain_content\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0melement\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mclick\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mF:\\Anaconda3\\lib\\site-packages\\selenium\\webdriver\\remote\\webelement.py\u001b[0m in \u001b[0;36mclick\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m     78\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0mclick\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     79\u001b[0m         \u001b[1;34m\"\"\"Clicks the element.\"\"\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 80\u001b[1;33m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_execute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mCommand\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mCLICK_ELEMENT\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     81\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     82\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0msubmit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mF:\\Anaconda3\\lib\\site-packages\\selenium\\webdriver\\remote\\webelement.py\u001b[0m in \u001b[0;36m_execute\u001b[1;34m(self, command, params)\u001b[0m\n\u001b[0;32m    631\u001b[0m             \u001b[0mparams\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m{\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    632\u001b[0m         \u001b[0mparams\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'id'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_id\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 633\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_parent\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcommand\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    634\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    635\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0mfind_element\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mby\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mBy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mID\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mF:\\Anaconda3\\lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py\u001b[0m in \u001b[0;36mexecute\u001b[1;34m(self, driver_command, params)\u001b[0m\n\u001b[0;32m    319\u001b[0m         \u001b[0mresponse\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcommand_executor\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdriver_command\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    320\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mresponse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 321\u001b[1;33m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0merror_handler\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcheck_response\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresponse\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    322\u001b[0m             response['value'] = self._unwrap_value(\n\u001b[0;32m    323\u001b[0m                 response.get('value', None))\n",
      "\u001b[1;32mF:\\Anaconda3\\lib\\site-packages\\selenium\\webdriver\\remote\\errorhandler.py\u001b[0m in \u001b[0;36mcheck_response\u001b[1;34m(self, response)\u001b[0m\n\u001b[0;32m    240\u001b[0m                 \u001b[0malert_text\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'alert'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'text'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    241\u001b[0m             \u001b[1;32mraise\u001b[0m \u001b[0mexception_class\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmessage\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mscreen\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstacktrace\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0malert_text\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 242\u001b[1;33m         \u001b[1;32mraise\u001b[0m \u001b[0mexception_class\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmessage\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mscreen\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstacktrace\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    243\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    244\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m_value_or_default\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mobj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdefault\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mElementNotInteractableException\u001b[0m: Message: element not interactable\n  (Session info: chrome=81.0.4044.138)\n"
     ]
    }
   ],
   "source": [
    "element = driver.find_element_by_xpath('//*[text()[contains(.,\"超链接\")]]') \n",
    "main_content = element.get_attribute('innerHTML')\n",
    "print(main_content)\n",
    "element.click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "选择其他公众号\n"
     ]
    }
   ],
   "source": [
    "# 点 选择其他公众号\n",
    "element = driver.find_element_by_xpath('//*[text()[contains(.,\"选择其他公众号\")]]') \n",
    "main_content = element.get_attribute('innerHTML')\n",
    "print(main_content)\n",
    "element.click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.find_element_by_xpath('//form//div[@class=\"inner_link_account_area\"]//input[@class=\"weui-desktop-form__input\"]').clear()\n",
    "driver.find_element_by_xpath('//form//div[@class=\"inner_link_account_area\"]//input[@class=\"weui-desktop-form__input\"]').send_keys(公众号)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<div class=\"weui-desktop-icon weui-desktop-icon__inputSearch weui-desktop-icon__small\"><!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M11.33 10.007l4.273 4.273a.502.502 0 0 1 .005.709l-.585.584a.499.499 0 0 1-.709-.004L10.046 11.3a6.278 6.278 0 1 1 1.284-1.294zm.012-3.729a5.063 5.063 0 1 0-10.127 0 5.063 5.063 0 0 0 10.127 0z\"></path></svg> <!----> <!----> <!----> <!----></div>\n"
     ]
    }
   ],
   "source": [
    "# 点放大镜搜\n",
    "element = driver.find_element_by_xpath('//button[@class=\"weui-desktop-icon-btn weui-desktop-search__btn\"]')\n",
    "main_content = element.get_attribute('innerHTML')\n",
    "print(main_content)\n",
    "element.click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<li class=\"inner_link_account_item\"><div class=\"weui-desktop-vm_primary\"><img src=\"http://mmbiz.qpic.cn/mmbiz_png/zWvuQpwibS7PMGRTfI1xwWibc680nMu6ibRsHxcoPibwExYT2t5QvibtZpbnT2tB187YDgJXp87FSjCNIa1sVwanldQ/0?wx_fmt=png\" class=\"inner_link_account_avatar\"> <strong class=\"inner_link_account_nickname\">广东省教育考试院</strong> <i class=\"inner_link_account_wechat\">微信号：gdsksy</i></div> <div class=\"weui-desktop-vm_default inner_link_account_type\">订阅号</div></li><li class=\"inner_link_account_item\"><div class=\"weui-desktop-vm_primary\"><img src=\"http://mmbiz.qpic.cn/mmbiz_png/q6ORm6wdYOFeltxabLj7JtjatcHdWn0nmcfso44sQ3bdQhehC9gg8nHNCRE68A9znHa1ACYcBsMpREh5GxtPAA/0?wx_fmt=png\" class=\"inner_link_account_avatar\"> <strong class=\"inner_link_account_nickname\">卓越教育考试研究院</strong> <i class=\"inner_link_account_wechat\">微信号：zyksyjy</i></div> <div class=\"weui-desktop-vm_default inner_link_account_type\">订阅号</div></li><li class=\"inner_link_account_item\"><div class=\"weui-desktop-vm_primary\"><img src=\"http://mmbiz.qpic.cn/mmbiz_png/BSg0B6TNfFhl72NkG8yPUda6OOopf2AcH5NtblhGGCXibgP7SKfh4ObQeCib3HNoKln5m4l0BiajhjCrx2OxRN97A/0?wx_fmt=png\" class=\"inner_link_account_avatar\"> <strong class=\"inner_link_account_nickname\">安徽省教育招生考试院</strong> <i class=\"inner_link_account_wechat\">微信号：ahsjyzsksy</i></div> <div class=\"weui-desktop-vm_default inner_link_account_type\">订阅号</div></li><li class=\"inner_link_account_item\"><div class=\"weui-desktop-vm_primary\"><img src=\"http://mmbiz.qpic.cn/mmbiz_png/MILkKUf2AxSxYOBfQsGjpKkTbs2iaqrqQlCpprud0803B71w1ibDKfpmNobUEXyO37oJpluPz4T1dpWeaicrvcj0g/0?wx_fmt=png\" class=\"inner_link_account_avatar\"> <strong class=\"inner_link_account_nickname\">四川省教育考试院</strong> <i class=\"inner_link_account_wechat\">微信号：scsjyksy</i></div> <div class=\"weui-desktop-vm_default inner_link_account_type\">订阅号</div></li><li class=\"inner_link_account_item\"><div class=\"weui-desktop-vm_primary\"><img src=\"http://mmbiz.qpic.cn/mmbiz_png/jCYmMvhLQr2VXxicicHpk6YHOkKKeWafeibSRbNVdtvn99CFhOicTJibWuriaP6YWYkAa6O4QbR04nt98rMB64ap3YRQ/0?wx_fmt=png\" class=\"inner_link_account_avatar\"> <strong class=\"inner_link_account_nickname\">职大成考教育考试院</strong> <i class=\"inner_link_account_wechat\">微信号：zd82683999</i></div> <div class=\"weui-desktop-vm_default inner_link_account_type\">服务号</div></li>\n"
     ]
    }
   ],
   "source": [
    "element = driver.find_element_by_xpath('//ul[@class=\"inner_link_account_list\"]')\n",
    "main_content = element.get_attribute('innerHTML')\n",
    "print(main_content)\n",
    "公众号SERP = main_content\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 解析\n",
    "root = fromstring(公众号SERP) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "主 = root.xpath('//li[@class=\"inner_link_account_item\"]')\n",
    "\n",
    "account_list = []\n",
    "for e in 主:\n",
    "    account_nickname = e.xpath('./div/strong[@class=\"inner_link_account_nickname\"]')[0].text\n",
    "    account_wechat = e.xpath('./div/i[@class=\"inner_link_account_wechat\"]')[0].text\n",
    "    account_img = e.xpath('./div/img/@src')[0]\n",
    "    account = {\"nickname\": account_nickname, \"wechat\": account_wechat, \"img\": account_img,}\n",
    "    account_list.append(account)\n",
    "\n",
    "df_account = pd.DataFrame(account_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>nickname</th>\n",
       "      <th>wechat</th>\n",
       "      <th>img</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>广东省教育考试院</td>\n",
       "      <td>微信号：gdsksy</td>\n",
       "      <td>http://mmbiz.qpic.cn/mmbiz_png/zWvuQpwibS7PMGR...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>卓越教育考试研究院</td>\n",
       "      <td>微信号：zyksyjy</td>\n",
       "      <td>http://mmbiz.qpic.cn/mmbiz_png/q6ORm6wdYOFeltx...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>安徽省教育招生考试院</td>\n",
       "      <td>微信号：ahsjyzsksy</td>\n",
       "      <td>http://mmbiz.qpic.cn/mmbiz_png/BSg0B6TNfFhl72N...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>四川省教育考试院</td>\n",
       "      <td>微信号：scsjyksy</td>\n",
       "      <td>http://mmbiz.qpic.cn/mmbiz_png/MILkKUf2AxSxYOB...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>职大成考教育考试院</td>\n",
       "      <td>微信号：zd82683999</td>\n",
       "      <td>http://mmbiz.qpic.cn/mmbiz_png/jCYmMvhLQr2VXxi...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     nickname          wechat  \\\n",
       "0    广东省教育考试院      微信号：gdsksy   \n",
       "1   卓越教育考试研究院     微信号：zyksyjy   \n",
       "2  安徽省教育招生考试院  微信号：ahsjyzsksy   \n",
       "3    四川省教育考试院    微信号：scsjyksy   \n",
       "4   职大成考教育考试院  微信号：zd82683999   \n",
       "\n",
       "                                                 img  \n",
       "0  http://mmbiz.qpic.cn/mmbiz_png/zWvuQpwibS7PMGR...  \n",
       "1  http://mmbiz.qpic.cn/mmbiz_png/q6ORm6wdYOFeltx...  \n",
       "2  http://mmbiz.qpic.cn/mmbiz_png/BSg0B6TNfFhl72N...  \n",
       "3  http://mmbiz.qpic.cn/mmbiz_png/MILkKUf2AxSxYOB...  \n",
       "4  http://mmbiz.qpic.cn/mmbiz_png/jCYmMvhLQr2VXxi...  "
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_account"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<div class=\"weui-desktop-vm_primary\"><img src=\"http://mmbiz.qpic.cn/mmbiz_png/zWvuQpwibS7PMGRTfI1xwWibc680nMu6ibRsHxcoPibwExYT2t5QvibtZpbnT2tB187YDgJXp87FSjCNIa1sVwanldQ/0?wx_fmt=png\" class=\"inner_link_account_avatar\"> <strong class=\"inner_link_account_nickname\">广东省教育考试院</strong> <i class=\"inner_link_account_wechat\">微信号：gdsksy</i></div> <div class=\"weui-desktop-vm_default inner_link_account_type\">订阅号</div>\n"
     ]
    }
   ],
   "source": [
    "element = driver.find_element_by_xpath('//ul[@class=\"inner_link_account_list\"]/li')\n",
    "main_content = element.get_attribute('innerHTML')\n",
    "print(main_content)\n",
    "element.click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\n跳转_input = driver.find_element_by_xpath(\\'//span[@class=\"weui-desktop-pagination__form\"]/input\\')\\n跳转_a = driver.find_element_by_xpath(\\'//span[@class=\"weui-desktop-pagination__form\"]/a\\')\\n跳转_input.clear()\\n跳转_input.send_keys(2)\\n跳转_a.click()\\n'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 跳转testing\n",
    "'''\n",
    "跳转_input = driver.find_element_by_xpath('//span[@class=\"weui-desktop-pagination__form\"]/input')\n",
    "跳转_a = driver.find_element_by_xpath('//span[@class=\"weui-desktop-pagination__form\"]/a')\n",
    "跳转_input.clear()\n",
    "跳转_input.send_keys(2)\n",
    "跳转_a.click()\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 186]\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "# 跳转上限\n",
    "l_e = driver.find_elements_by_xpath('//label[@class=\"weui-desktop-pagination__num\"]')\n",
    "l_e_int  = [int(x.text) for x in l_e] \n",
    "print (l_e_int)\n",
    "print (l_e_int[0]==l_e_int[-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186]\n",
      "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80]\n"
     ]
    }
   ],
   "source": [
    "pages = list(range(l_e_int[0],l_e_int[-1]+1 ))\n",
    "#print(pages[0:2])\n",
    "pages = list(range(1,l_e_int[-1]+1 ))\n",
    "print(pages)\n",
    "pages_cut=print(pages[0:80])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 循环/遍历"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "# global varialbes \n",
    "html_raw = dict()\n",
    "main_content =\"\"\n",
    "element = None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "def process_pages (pages_cut):\n",
    "    for p in pages:\n",
    "        print (p,end='\\t')\n",
    "\n",
    "        跳转_input = driver.find_element_by_xpath('//span[@class=\"weui-desktop-pagination__form\"]/input')\n",
    "        跳转_a = driver.find_element_by_xpath('//span[@class=\"weui-desktop-pagination__form\"]/a')\n",
    "        跳转_input.clear()\n",
    "        跳转_input.send_keys(p)\n",
    "        跳转_a.click()\n",
    "\n",
    "        time.sleep(3+4*random())\n",
    "\n",
    "        element = driver.find_element_by_xpath('//div[@class=\"inner_link_article_list\"]')\n",
    "        main_content = element.get_attribute('innerHTML')\n",
    "        #print(main_content)\n",
    "        html_raw[p] = main_content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\t2\t3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\t22\t23\t24\t25\t26\t27\t28\t29\t30\t31\t32\t33\t34\t35\t36\t37\t38\t39\t40\t41\t42\t43\t44\t45\t46\t47\t48\t49\t50\t51\t52\t53\t54\t55\t56\t57\t58\t59\t60\t61\t62\t63\t64\t65\t66\t67\t68\t69\t70\t71\t72\t73\t74\t75\t76\t77\t78\t79\t80\t81\t82\t83\t84\t85\t86\t87\t88\t89\t90\t91\t92\t93\t94\t95\t96\t97\t98\t99\t100\t101\t102\t103\t104\t105\t106\t107\t108\t109\t110\t111\t112\t113\t114\t115\t116\t117\t118\t119\t120\t121\t122\t123\t124\t125\t126\t127\t128\t129\t130\t131\t132\t133\t134\t135\t136\t137\t138\t139\t140\t141\t142\t143\t144\t145\t146\t147\t148\t149\t150\t151\t152\t153\t154\t155\t156\t157\t158\t159\t160\t161\t162\t163\t164\t165\t166\t167\t168\t169\t170\t171\t172\t173\t174\t175\t176\t177\t178\t179\t180\t181\t182\t183\t184\t185\t186\t"
     ]
    }
   ],
   "source": [
    "process_pages(pages_cut)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>html_snippets</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>182</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>183</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>184</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>185</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>186</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>186 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         html_snippets\n",
       "1    <div><label class=\"inner_link_article_item\"><s...\n",
       "2    <div><label class=\"inner_link_article_item\"><s...\n",
       "3    <div><label class=\"inner_link_article_item\"><s...\n",
       "4    <div><label class=\"inner_link_article_item\"><s...\n",
       "5    <div><label class=\"inner_link_article_item\"><s...\n",
       "..                                                 ...\n",
       "182  <div><label class=\"inner_link_article_item\"><s...\n",
       "183  <div><label class=\"inner_link_article_item\"><s...\n",
       "184  <div><label class=\"inner_link_article_item\"><s...\n",
       "185  <div><label class=\"inner_link_article_item\"><s...\n",
       "186  <div><label class=\"inner_link_article_item\"><s...\n",
       "\n",
       "[186 rows x 1 columns]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame([html_raw]).T\n",
    "df.columns = [\"html_snippets\"]\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Stored 'html_raw' (dict)\n"
     ]
    }
   ],
   "source": [
    "%store html_raw\n",
    "import pickle \n",
    "filehandler = open(\"html_raw\", 'wb') \n",
    "pickle.dump(html_raw, filehandler)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "68\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>html_snippets</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>182</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>183</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>184</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>185</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>186</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>118 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         html_snippets\n",
       "12   <div><label class=\"inner_link_article_item\"><s...\n",
       "70   <div><label class=\"inner_link_article_item\"><s...\n",
       "71   <div><label class=\"inner_link_article_item\"><s...\n",
       "72   <div><label class=\"inner_link_article_item\"><s...\n",
       "73   <div><label class=\"inner_link_article_item\"><s...\n",
       "..                                                 ...\n",
       "182  <div><label class=\"inner_link_article_item\"><s...\n",
       "183  <div><label class=\"inner_link_article_item\"><s...\n",
       "184  <div><label class=\"inner_link_article_item\"><s...\n",
       "185  <div><label class=\"inner_link_article_item\"><s...\n",
       "186  <div><label class=\"inner_link_article_item\"><s...\n",
       "\n",
       "[118 rows x 1 columns]"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_out = df[~df.duplicated()]\n",
    "print (len(df_out))\n",
    "df[df.duplicated()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[12, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[12,\n",
       " 70,\n",
       " 71,\n",
       " 72,\n",
       " 73,\n",
       " 74,\n",
       " 75,\n",
       " 76,\n",
       " 77,\n",
       " 78,\n",
       " 79,\n",
       " 80,\n",
       " 81,\n",
       " 82,\n",
       " 83,\n",
       " 84,\n",
       " 85,\n",
       " 86,\n",
       " 87,\n",
       " 88,\n",
       " 89,\n",
       " 90,\n",
       " 91,\n",
       " 92,\n",
       " 93,\n",
       " 94,\n",
       " 95,\n",
       " 96,\n",
       " 97,\n",
       " 98,\n",
       " 99,\n",
       " 100,\n",
       " 101,\n",
       " 102,\n",
       " 103,\n",
       " 104,\n",
       " 105,\n",
       " 106,\n",
       " 107,\n",
       " 108,\n",
       " 109,\n",
       " 110,\n",
       " 111,\n",
       " 112,\n",
       " 113,\n",
       " 114,\n",
       " 115,\n",
       " 116,\n",
       " 117,\n",
       " 118,\n",
       " 119,\n",
       " 120,\n",
       " 121,\n",
       " 122,\n",
       " 123,\n",
       " 124,\n",
       " 125,\n",
       " 126,\n",
       " 127,\n",
       " 128,\n",
       " 129,\n",
       " 130,\n",
       " 131,\n",
       " 132,\n",
       " 133,\n",
       " 134,\n",
       " 135,\n",
       " 136,\n",
       " 137,\n",
       " 138,\n",
       " 139,\n",
       " 140,\n",
       " 141,\n",
       " 142,\n",
       " 143,\n",
       " 144,\n",
       " 145,\n",
       " 146,\n",
       " 147,\n",
       " 148,\n",
       " 149,\n",
       " 150,\n",
       " 151,\n",
       " 152,\n",
       " 153,\n",
       " 154,\n",
       " 155,\n",
       " 156,\n",
       " 157,\n",
       " 158,\n",
       " 159,\n",
       " 160,\n",
       " 161,\n",
       " 162,\n",
       " 163,\n",
       " 164,\n",
       " 165,\n",
       " 166,\n",
       " 167,\n",
       " 168,\n",
       " 169,\n",
       " 170,\n",
       " 171,\n",
       " 172,\n",
       " 173,\n",
       " 174,\n",
       " 175,\n",
       " 176,\n",
       " 177,\n",
       " 178,\n",
       " 179,\n",
       " 180,\n",
       " 181,\n",
       " 182,\n",
       " 183,\n",
       " 184,\n",
       " 185,\n",
       " 186]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "try_again = list(df[df.duplicated()].index)\n",
    "print(try_again)\n",
    "try_again = try_again + list (set(pages).difference(set(df.index.values)))\n",
    "try_again"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 暂存档"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "filename = fn [\"output\"] [\"公众号_htm_snippets\"] \n",
    "df_out.to_csv(filename.format(公众号=公众号), sep=\"\\t\", encoding=\"utf8\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13,14,19,17,13,11,14,14,15,14,13,14,17,17,20,18,20,14,17,16,13,11,14,18,20,17,19,11,20,17,17,18,20,20,20,13,17,17,20,15,11,14,13,13,12,20,20,20,20,20,13,17,13,14,13,19,16,15,17,14,11,14,16,17,8,14,18,20,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,"
     ]
    }
   ],
   "source": [
    "def parse_html_snippets(_snippet_):\n",
    "    root = fromstring(_snippet_) \n",
    "    title = [x.text for x in root.xpath('//div[@class=\"inner_link_article_title\"]')]\n",
    "    create_time = [x.text for x in root.xpath('//div[@class=\"inner_link_article_date\"]')]\n",
    "    link = [x for x in root.xpath('//a/@href')]\n",
    "    _df_ = pd.DataFrame({\"title\":title, \"create_time\": create_time, \"link\":link})\n",
    "    return(_df_)\n",
    "    \n",
    "l_df = []\n",
    "for p in pages:\n",
    "    _df_ = parse_html_snippets(df.loc[p,\"html_snippets\"])\n",
    "    print (len(_df_), end=\",\")\n",
    "    l_df.append(_df_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>关于2020年全国体育单招和高校高水平运动队招生部分项目专业统考有关考试安排的通知</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>我省2020年普通高考英语听说考试5月底进行，这些事情要注意</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>关于恢复开展我省上半年自考转考工作的公告</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>教育部发文，要求做好2020年招收攻读博士学位研究生工作</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>@家长，各地陆续复课，务必提防6种传染病！</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>关于做好2020年7月广东省普通高中学业水平合格性考试报名工作的通知</td>\n",
       "      <td>2020-05-14</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>​7项部署！教育部：科学精准防控疫情 推动全面复学复课</td>\n",
       "      <td>2020-05-14</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>教育部等八部门发文，加快构建高校思想政治工作体系 ​近日，教育部等八部门发布《关于加快构建高...</td>\n",
       "      <td>2020-05-14</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>人社部、教育部等4部门发文，要求做好2020年中小学幼儿园教师公开招聘工作​</td>\n",
       "      <td>2020-05-14</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>公布 | 复旦大学2020年强基计划招生简章</td>\n",
       "      <td>2020-05-13</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>复旦大学强基计划答考生问</td>\n",
       "      <td>2020-05-13</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                title create_time  \\\n",
       "0           关于2020年全国体育单招和高校高水平运动队招生部分项目专业统考有关考试安排的通知  2020-05-15   \n",
       "1                      我省2020年普通高考英语听说考试5月底进行，这些事情要注意  2020-05-15   \n",
       "2                                关于恢复开展我省上半年自考转考工作的公告  2020-05-15   \n",
       "3                        教育部发文，要求做好2020年招收攻读博士学位研究生工作  2020-05-15   \n",
       "4                               @家长，各地陆续复课，务必提防6种传染病！  2020-05-15   \n",
       "5                  关于做好2020年7月广东省普通高中学业水平合格性考试报名工作的通知  2020-05-14   \n",
       "6                         ​7项部署！教育部：科学精准防控疫情 推动全面复学复课  2020-05-14   \n",
       "7   教育部等八部门发文，加快构建高校思想政治工作体系 ​近日，教育部等八部门发布《关于加快构建高...  2020-05-14   \n",
       "8              人社部、教育部等4部门发文，要求做好2020年中小学幼儿园教师公开招聘工作​  2020-05-14   \n",
       "9                              公布 | 复旦大学2020年强基计划招生简章  2020-05-13   \n",
       "10                                       复旦大学强基计划答考生问  2020-05-13   \n",
       "\n",
       "                                                 link  \n",
       "0   http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "1   http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "2   http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "3   http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "4   http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "5   http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "6   http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "7   http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "8   http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "9   http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "10  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  "
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_url_out = pd.concat(l_df).reset_index(drop=True)\n",
    "df_url_out.loc[0:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3080</th>\n",
       "      <td>点赞叶嘉莹！中国最后一个穿裙子的先生，95岁再捐1711万，只为中国诗心生生不息</td>\n",
       "      <td>2019-05-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3081</th>\n",
       "      <td>2019年上半年(第54次)全国计算机等级考试成绩公布啦！</td>\n",
       "      <td>2019-05-16</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3082</th>\n",
       "      <td>广东省高等教育自学考试专业考试计划—视觉传播设计与制作（专科）</td>\n",
       "      <td>2019-05-16</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3083</th>\n",
       "      <td>教育部：不准将毕业证书、学位证书发放与毕业生签约挂钩</td>\n",
       "      <td>2019-05-16</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3084</th>\n",
       "      <td>明确8项工作任务，教育部等6部门发布《高职扩招专项工作实施方案》</td>\n",
       "      <td>2019-05-16</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         title create_time  \\\n",
       "3080  点赞叶嘉莹！中国最后一个穿裙子的先生，95岁再捐1711万，只为中国诗心生生不息  2019-05-17   \n",
       "3081             2019年上半年(第54次)全国计算机等级考试成绩公布啦！  2019-05-16   \n",
       "3082           广东省高等教育自学考试专业考试计划—视觉传播设计与制作（专科）  2019-05-16   \n",
       "3083                教育部：不准将毕业证书、学位证书发放与毕业生签约挂钩  2019-05-16   \n",
       "3084          明确8项工作任务，教育部等6部门发布《高职扩招专项工作实施方案》  2019-05-16   \n",
       "\n",
       "                                                   link  \n",
       "3080  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "3081  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "3082  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "3083  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "3084  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  "
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_url_out.tail(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 214,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>value</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>复旦大学强基计划答考生问</td>\n",
       "      <td>2020-05-13</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>细说复旦强基计划之一：远大目标</td>\n",
       "      <td>2020-05-13</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>一图了解复旦大学强基计划</td>\n",
       "      <td>2020-05-13</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>广东省教育厅通告</td>\n",
       "      <td>2020-03-26</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>“牵手工程”持续推进！广东115所学校与凉山、怒江、甘孜学校结对子</td>\n",
       "      <td>2020-03-24</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3063</th>\n",
       "      <td>点赞叶嘉莹！中国最后一个穿裙子的先生，95岁再捐1711万，只为中国诗心生生不息</td>\n",
       "      <td>2019-05-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3068</th>\n",
       "      <td>加强党建交流  促进融合发展</td>\n",
       "      <td>2019-05-21</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3071</th>\n",
       "      <td>每个姓氏都有一首诗词，你属于哪首？</td>\n",
       "      <td>2019-05-21</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3079</th>\n",
       "      <td>教育部长陈宝生：让教育为人类文明传承创新服务</td>\n",
       "      <td>2019-05-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3080</th>\n",
       "      <td>点赞叶嘉莹！中国最后一个穿裙子的先生，95岁再捐1711万，只为中国诗心生生不息</td>\n",
       "      <td>2019-05-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>768 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                          title create_time  \\\n",
       "value                                                         \n",
       "10                                 复旦大学强基计划答考生问  2020-05-13   \n",
       "11                              细说复旦强基计划之一：远大目标  2020-05-13   \n",
       "12                                 一图了解复旦大学强基计划  2020-05-13   \n",
       "13                                     广东省教育厅通告  2020-03-26   \n",
       "24            “牵手工程”持续推进！广东115所学校与凉山、怒江、甘孜学校结对子  2020-03-24   \n",
       "...                                         ...         ...   \n",
       "3063   点赞叶嘉莹！中国最后一个穿裙子的先生，95岁再捐1711万，只为中国诗心生生不息  2019-05-17   \n",
       "3068                             加强党建交流  促进融合发展  2019-05-21   \n",
       "3071                          每个姓氏都有一首诗词，你属于哪首？  2019-05-21   \n",
       "3079                     教育部长陈宝生：让教育为人类文明传承创新服务  2019-05-17   \n",
       "3080   点赞叶嘉莹！中国最后一个穿裙子的先生，95岁再捐1711万，只为中国诗心生生不息  2019-05-17   \n",
       "\n",
       "                                                    link  \n",
       "value                                                     \n",
       "10     http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "11     http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "12     http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "13     http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "24     http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "...                                                  ...  \n",
       "3063   http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "3068   http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "3071   http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "3079   http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "3080   http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "\n",
       "[768 rows x 3 columns]"
      ]
     },
     "execution_count": 214,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# tagging 标记\n",
    "tagging_list = [\"\",\"高考\",\"中考\",\"招生\",\"招聘\",\"就业\",\"创业\"\"教育脱贫\",\"教师资格考试\",\"计算机等级考试\",\"艺考\",\\\n",
    "                \"高中\",\"初中\",\"毕业\",\"自考\",\"自学考试\",\"研究生\",\"高校\",\"中小学\",\"考研\",\"志愿\",\\\n",
    "                \"听说考试\",\"图片\",\"照片\",\"小编\",\"方案\",\\\n",
    "                \"被骗\",\"腾讯安全课\",\"诈骗\", '粤课堂',\"线上教育\",\"线上学习\",\\\n",
    "                \"报告\",\"发布\",\"报名\",\"公告\",\"公布\",\"通知\",\"出台\",\\\n",
    "                \"体育\",\"老师\",\"家长\",\\\n",
    "                \"国家奖学金\",\"英语等级考试\",\"英语四、六级考试\",\"书画等级考试\",\"美术统考\",\"线上\",\\\n",
    "                \"数据\", \"数据赋能\", \"智能\", \"数字孪生\", \"智慧大脑\",\\\n",
    "                \"出行\",\"乘车\",\"公交\",\"乘车码\", \"智慧地铁\",\\\n",
    "                \"高峰论坛\", \"智库\",\\\n",
    "                \"微信\", \"微信支付\", \"跨境支付\", \"移动支付\",\"非银行支付\",\"电子支付\",\\\n",
    "                \"互联网金融\", \"金融科技\",\"互联网＋\",\"互联网+金融\",\"普惠金融\",\"虚拟银行\",\\\n",
    "                \"开放\",\"生态\",\"复杂\",\"互联网思维\",\"全球合作伙伴\",\\\n",
    "                \"联合国\", \"城市\", \"粤港澳大湾区\", \"平台\", \"可持续发展\", \"未来\", \"绿色\",\\\n",
    "                \"医护\",\"防护服\",\"小时\",\"武汉\",\"危机\",\"新冠肺炎\", \"疫\", \"疫情\", \"复工\",\"返校\",\"复课\",\"停课\",\"宅经济\",\\\n",
    "                \"基建\",\"新基建\",\"贫困\"] #overwritable\n",
    "\n",
    "v_v_list = []\n",
    "\n",
    "for tag in tagging_list:\n",
    "    index_list = df_url_out [ df_url_out.title.str.contains(tag) ].index.tolist()\n",
    "    v_v_pairs = pd.DataFrame({tag:index_list}).melt().set_index(\"value\")\n",
    "    v_v_list.append(v_v_pairs)\n",
    "\n",
    "df_cat = v_v_list[0]\n",
    "for d in v_v_list:\n",
    "    df_cat.update(d)\n",
    "    \n",
    "# 尚未标记内容\n",
    "df_url_out.loc [ df_cat.query('variable==\"\"').index ]"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "df_url_out.loc[53].link"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 215,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>157</th>\n",
       "      <td>广东省教育厅通告</td>\n",
       "      <td>2020-03-26</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>158</th>\n",
       "      <td>关于做好2020年普通高校春季高考志愿填报工作的通知</td>\n",
       "      <td>2020-03-26</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159</th>\n",
       "      <td>2020艺考咨询，考生都关心哪些问题？</td>\n",
       "      <td>2020-03-26</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>160</th>\n",
       "      <td>​教育部启动实施高校银龄教师支援西部计划，5问答详解</td>\n",
       "      <td>2020-03-26</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>161</th>\n",
       "      <td>关于推迟广东省2020年高等职业院校自主招生工作时间的通知</td>\n",
       "      <td>2020-03-25</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3080</th>\n",
       "      <td>点赞叶嘉莹！中国最后一个穿裙子的先生，95岁再捐1711万，只为中国诗心生生不息</td>\n",
       "      <td>2019-05-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3081</th>\n",
       "      <td>2019年上半年(第54次)全国计算机等级考试成绩公布啦！</td>\n",
       "      <td>2019-05-16</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3082</th>\n",
       "      <td>广东省高等教育自学考试专业考试计划—视觉传播设计与制作（专科）</td>\n",
       "      <td>2019-05-16</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3083</th>\n",
       "      <td>教育部：不准将毕业证书、学位证书发放与毕业生签约挂钩</td>\n",
       "      <td>2019-05-16</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3084</th>\n",
       "      <td>明确8项工作任务，教育部等6部门发布《高职扩招专项工作实施方案》</td>\n",
       "      <td>2019-05-16</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2003 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         title create_time  \\\n",
       "157                                   广东省教育厅通告  2020-03-26   \n",
       "158                 关于做好2020年普通高校春季高考志愿填报工作的通知  2020-03-26   \n",
       "159                        2020艺考咨询，考生都关心哪些问题？  2020-03-26   \n",
       "160                 ​教育部启动实施高校银龄教师支援西部计划，5问答详解  2020-03-26   \n",
       "161              关于推迟广东省2020年高等职业院校自主招生工作时间的通知  2020-03-25   \n",
       "...                                        ...         ...   \n",
       "3080  点赞叶嘉莹！中国最后一个穿裙子的先生，95岁再捐1711万，只为中国诗心生生不息  2019-05-17   \n",
       "3081             2019年上半年(第54次)全国计算机等级考试成绩公布啦！  2019-05-16   \n",
       "3082           广东省高等教育自学考试专业考试计划—视觉传播设计与制作（专科）  2019-05-16   \n",
       "3083                教育部：不准将毕业证书、学位证书发放与毕业生签约挂钩  2019-05-16   \n",
       "3084          明确8项工作任务，教育部等6部门发布《高职扩招专项工作实施方案》  2019-05-16   \n",
       "\n",
       "                                                   link  \n",
       "157   http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "158   http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "159   http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "160   http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "161   http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "...                                                 ...  \n",
       "3080  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "3081  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "3082  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "3083  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "3084  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "\n",
       "[2003 rows x 3 columns]"
      ]
     },
     "execution_count": 215,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_url_out[df_url_out.duplicated()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 216,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>关于2020年全国体育单招和高校高水平运动队招生部分项目专业统考有关考试安排的通知</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>我省2020年普通高考英语听说考试5月底进行，这些事情要注意</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>关于恢复开展我省上半年自考转考工作的公告</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>教育部发文，要求做好2020年招收攻读博士学位研究生工作</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>@家长，各地陆续复课，务必提防6种传染病！</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1091</th>\n",
       "      <td>点赞叶嘉莹！中国最后一个穿裙子的先生，95岁再捐1711万，只为中国诗心生生不息</td>\n",
       "      <td>2019-05-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1092</th>\n",
       "      <td>2019年上半年(第54次)全国计算机等级考试成绩公布啦！</td>\n",
       "      <td>2019-05-16</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1093</th>\n",
       "      <td>广东省高等教育自学考试专业考试计划—视觉传播设计与制作（专科）</td>\n",
       "      <td>2019-05-16</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1094</th>\n",
       "      <td>教育部：不准将毕业证书、学位证书发放与毕业生签约挂钩</td>\n",
       "      <td>2019-05-16</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1095</th>\n",
       "      <td>明确8项工作任务，教育部等6部门发布《高职扩招专项工作实施方案》</td>\n",
       "      <td>2019-05-16</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1082 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                          title create_time  \\\n",
       "0     关于2020年全国体育单招和高校高水平运动队招生部分项目专业统考有关考试安排的通知  2020-05-15   \n",
       "1                我省2020年普通高考英语听说考试5月底进行，这些事情要注意  2020-05-15   \n",
       "2                          关于恢复开展我省上半年自考转考工作的公告  2020-05-15   \n",
       "3                  教育部发文，要求做好2020年招收攻读博士学位研究生工作  2020-05-15   \n",
       "4                         @家长，各地陆续复课，务必提防6种传染病！  2020-05-15   \n",
       "...                                         ...         ...   \n",
       "1091   点赞叶嘉莹！中国最后一个穿裙子的先生，95岁再捐1711万，只为中国诗心生生不息  2019-05-17   \n",
       "1092              2019年上半年(第54次)全国计算机等级考试成绩公布啦！  2019-05-16   \n",
       "1093            广东省高等教育自学考试专业考试计划—视觉传播设计与制作（专科）  2019-05-16   \n",
       "1094                 教育部：不准将毕业证书、学位证书发放与毕业生签约挂钩  2019-05-16   \n",
       "1095           明确8项工作任务，教育部等6部门发布《高职扩招专项工作实施方案》  2019-05-16   \n",
       "\n",
       "                                                   link  \n",
       "0     http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "1     http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "2     http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "3     http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "4     http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "...                                                 ...  \n",
       "1091  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "1092  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "1093  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "1094  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "1095  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...  \n",
       "\n",
       "[1082 rows x 3 columns]"
      ]
     },
     "execution_count": 216,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_url_out[~df_url_out.duplicated()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 217,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "      <th>variable</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>关于2020年全国体育单招和高校高水平运动队招生部分项目专业统考有关考试安排的通知</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "      <td>体育</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>我省2020年普通高考英语听说考试5月底进行，这些事情要注意</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "      <td>听说考试</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>关于恢复开展我省上半年自考转考工作的公告</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "      <td>公告</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>教育部发文，要求做好2020年招收攻读博士学位研究生工作</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "      <td>研究生</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>@家长，各地陆续复课，务必提防6种传染病！</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "      <td>复课</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3080</th>\n",
       "      <td>点赞叶嘉莹！中国最后一个穿裙子的先生，95岁再捐1711万，只为中国诗心生生不息</td>\n",
       "      <td>2019-05-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "      <td>无法分类</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3081</th>\n",
       "      <td>2019年上半年(第54次)全国计算机等级考试成绩公布啦！</td>\n",
       "      <td>2019-05-16</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "      <td>公布</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3082</th>\n",
       "      <td>广东省高等教育自学考试专业考试计划—视觉传播设计与制作（专科）</td>\n",
       "      <td>2019-05-16</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "      <td>自学考试</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3083</th>\n",
       "      <td>教育部：不准将毕业证书、学位证书发放与毕业生签约挂钩</td>\n",
       "      <td>2019-05-16</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "      <td>毕业</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3084</th>\n",
       "      <td>明确8项工作任务，教育部等6部门发布《高职扩招专项工作实施方案》</td>\n",
       "      <td>2019-05-16</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "      <td>发布</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3085 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                          title create_time  \\\n",
       "0     关于2020年全国体育单招和高校高水平运动队招生部分项目专业统考有关考试安排的通知  2020-05-15   \n",
       "1                我省2020年普通高考英语听说考试5月底进行，这些事情要注意  2020-05-15   \n",
       "2                          关于恢复开展我省上半年自考转考工作的公告  2020-05-15   \n",
       "3                  教育部发文，要求做好2020年招收攻读博士学位研究生工作  2020-05-15   \n",
       "4                         @家长，各地陆续复课，务必提防6种传染病！  2020-05-15   \n",
       "...                                         ...         ...   \n",
       "3080   点赞叶嘉莹！中国最后一个穿裙子的先生，95岁再捐1711万，只为中国诗心生生不息  2019-05-17   \n",
       "3081              2019年上半年(第54次)全国计算机等级考试成绩公布啦！  2019-05-16   \n",
       "3082            广东省高等教育自学考试专业考试计划—视觉传播设计与制作（专科）  2019-05-16   \n",
       "3083                 教育部：不准将毕业证书、学位证书发放与毕业生签约挂钩  2019-05-16   \n",
       "3084           明确8项工作任务，教育部等6部门发布《高职扩招专项工作实施方案》  2019-05-16   \n",
       "\n",
       "                                                   link variable  \n",
       "0     http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...       体育  \n",
       "1     http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...     听说考试  \n",
       "2     http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...       公告  \n",
       "3     http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...      研究生  \n",
       "4     http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...       复课  \n",
       "...                                                 ...      ...  \n",
       "3080  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...     无法分类  \n",
       "3081  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...       公布  \n",
       "3082  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...     自学考试  \n",
       "3083  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...       毕业  \n",
       "3084  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...       发布  \n",
       "\n",
       "[3085 rows x 4 columns]"
      ]
     },
     "execution_count": 217,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_o = df_url_out.join(df_cat).replace(\"\", np.nan).fillna(\"无法分类\")\n",
    "df_o"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 218,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "      <th>variable</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>我省2020年普通高考英语听说考试5月底进行，这些事情要注意</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "      <td>听说考试</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>关于做好2020年普通高校春季高考志愿填报工作的通知</td>\n",
       "      <td>2020-03-26</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "      <td>通知</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>@高考生，广东省2020年春季高考线上咨询会3月31日正式开启</td>\n",
       "      <td>2020-03-25</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "      <td>线上</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>清华等六校联合助力国家专项计划考生备战高考</td>\n",
       "      <td>2020-03-25</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "      <td>高考</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>我省2020年春季高考“依学考成绩录取”第一次投档录取结束</td>\n",
       "      <td>2020-04-18</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "      <td>高考</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3041</th>\n",
       "      <td>距离高考不足1个月！这份冲刺复习攻略一定要告诉孩子</td>\n",
       "      <td>2019-05-20</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "      <td>高考</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3053</th>\n",
       "      <td>5月高考热点：招生章程、名单公示、熟悉志愿填报政策</td>\n",
       "      <td>2019-05-21</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "      <td>志愿</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3058</th>\n",
       "      <td>距离高考不足1个月！这份冲刺复习攻略一定要告诉孩子</td>\n",
       "      <td>2019-05-20</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "      <td>高考</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3070</th>\n",
       "      <td>5月高考热点：招生章程、名单公示、熟悉志愿填报政策</td>\n",
       "      <td>2019-05-21</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "      <td>志愿</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3075</th>\n",
       "      <td>距离高考不足1个月！这份冲刺复习攻略一定要告诉孩子</td>\n",
       "      <td>2019-05-20</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...</td>\n",
       "      <td>高考</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>352 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                title create_time  \\\n",
       "1      我省2020年普通高考英语听说考试5月底进行，这些事情要注意  2020-05-15   \n",
       "14         关于做好2020年普通高校春季高考志愿填报工作的通知  2020-03-26   \n",
       "18    @高考生，广东省2020年春季高考线上咨询会3月31日正式开启  2020-03-25   \n",
       "20              清华等六校联合助力国家专项计划考生备战高考  2020-03-25   \n",
       "91      我省2020年春季高考“依学考成绩录取”第一次投档录取结束  2020-04-18   \n",
       "...                               ...         ...   \n",
       "3041        距离高考不足1个月！这份冲刺复习攻略一定要告诉孩子  2019-05-20   \n",
       "3053        5月高考热点：招生章程、名单公示、熟悉志愿填报政策  2019-05-21   \n",
       "3058        距离高考不足1个月！这份冲刺复习攻略一定要告诉孩子  2019-05-20   \n",
       "3070        5月高考热点：招生章程、名单公示、熟悉志愿填报政策  2019-05-21   \n",
       "3075        距离高考不足1个月！这份冲刺复习攻略一定要告诉孩子  2019-05-20   \n",
       "\n",
       "                                                   link variable  \n",
       "1     http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...     听说考试  \n",
       "14    http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...       通知  \n",
       "18    http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...       线上  \n",
       "20    http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...       高考  \n",
       "91    http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...       高考  \n",
       "...                                                 ...      ...  \n",
       "3041  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...       高考  \n",
       "3053  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...       志愿  \n",
       "3058  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...       高考  \n",
       "3070  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...       志愿  \n",
       "3075  http://mp.weixin.qq.com/s?__biz=MzI4NjYzMTM4MA...       高考  \n",
       "\n",
       "[352 rows x 4 columns]"
      ]
     },
     "execution_count": 218,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_o[df_o.title.str.contains(\"高考\")]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 219,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>variable</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>无法分类</th>\n",
       "      <td>768</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>自学考试</th>\n",
       "      <td>505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>毕业</th>\n",
       "      <td>255</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>公布</th>\n",
       "      <td>167</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>高考</th>\n",
       "      <td>166</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>志愿</th>\n",
       "      <td>153</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>发布</th>\n",
       "      <td>148</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>公告</th>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>自考</th>\n",
       "      <td>133</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>贫困</th>\n",
       "      <td>121</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>高校</th>\n",
       "      <td>73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>通知</th>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>疫情</th>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>招生</th>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>报名</th>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>线上</th>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>家长</th>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>中小学</th>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>返校</th>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>疫</th>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>体育</th>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>老师</th>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>高中</th>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>研究生</th>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>平台</th>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>书画等级考试</th>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>出台</th>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>复课</th>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>国家奖学金</th>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>英语等级考试</th>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>考研</th>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>诈骗</th>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>艺考</th>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>英语四、六级考试</th>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>方案</th>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>就业</th>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>停课</th>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>计算机等级考试</th>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>数据</th>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>出行</th>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>粤课堂</th>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>新冠肺炎</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>初中</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>开放</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>听说考试</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>联合国</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>绿色</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>粤港澳大湾区</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>生态</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>照片</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>未来</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>小时</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>招聘</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>武汉</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          title\n",
       "variable       \n",
       "无法分类        768\n",
       "自学考试        505\n",
       "毕业          255\n",
       "公布          167\n",
       "高考          166\n",
       "志愿          153\n",
       "发布          148\n",
       "公告          141\n",
       "自考          133\n",
       "贫困          121\n",
       "高校           73\n",
       "通知           55\n",
       "疫情           43\n",
       "招生           36\n",
       "报名           36\n",
       "线上           31\n",
       "家长           31\n",
       "中小学          27\n",
       "返校           19\n",
       "疫            18\n",
       "体育           17\n",
       "老师           13\n",
       "高中           12\n",
       "研究生          10\n",
       "平台            8\n",
       "书画等级考试        8\n",
       "出台            8\n",
       "复课            7\n",
       "国家奖学金         6\n",
       "英语等级考试        6\n",
       "考研            5\n",
       "诈骗            5\n",
       "艺考            5\n",
       "英语四、六级考试      5\n",
       "方案            5\n",
       "就业            5\n",
       "停课            4\n",
       "计算机等级考试       4\n",
       "数据            4\n",
       "出行            4\n",
       "粤课堂           3\n",
       "新冠肺炎          2\n",
       "初中            2\n",
       "开放            1\n",
       "听说考试          1\n",
       "联合国           1\n",
       "绿色            1\n",
       "粤港澳大湾区        1\n",
       "生态            1\n",
       "照片            1\n",
       "未来            1\n",
       "小时            1\n",
       "招聘            1\n",
       "武汉            1"
      ]
     },
     "execution_count": 219,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_stats = df_o.groupby(by=\"variable\").agg({\"title\":\"count\"}).sort_values(by=\"title\", ascending=False)\n",
    "df_stats"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 220,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_account.columns.name = \"rel_accounts\"\n",
    "df_o.columns.name = \"url_cat\"\n",
    "df_stats.columns.name = \"stats\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 221,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'stats'"
      ]
     },
     "execution_count": 221,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "_df_.columns.name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 222,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get the xlsxwriter workbook and worksheet objects.  \n",
    "with pd.ExcelWriter(fn[\"output\"][\"公众号_xlsx\"].format(公众号=公众号)) as writer:\n",
    "    workbook  = writer.book\n",
    "\n",
    "    for _df_ in [df_account, df_o, df_stats]:\n",
    "        _df_.to_excel(writer, sheet_name = _df_.columns.name)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
